package com.fanhang.samples.socket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class TalkClient {

	public static void main(String args[]) {
		try {
			Socket socket = new Socket("127.0.0.1", 9999);
			
			// 输出：到往server
			PrintWriter os = new PrintWriter(socket.getOutputStream());
			
			// 输入：来自server
			BufferedReader is = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		
			os.println("message test");
			os.flush();
			
			String input;
			while ((input = is.readLine()) != null) {
				System.out.println("Server:" + input);
			}
			
			os.close();
			is.close();
			
			socket.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
